/*****************************************************************************************
This file is a part of Arise library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

Arise Engine		Camera.h

					E-mail:	arise_engine@mail.ru

					Origin by DK Engine 0.019:
					dev (avon.dn.ua@gmail.com), Agressor (agress0r@mail.ru)

created:			10.06.2003
last changes:		01.03.2008
************************************************************************/
#pragma once

#include "Frustum.h"


#define VECTOR_UP_DEFAULT D3DXVECTOR3(0.0f, 1.0f, 0.0f)



class Camera
{
private:

	D3DXMATRIXA16	m_matrix_view;
	D3DXMATRIXA16	m_matrix_projection;
	D3DXVECTOR3		m_position;
	D3DXVECTOR3		m_target;
	D3DXVECTOR3		m_right;
	float			m_fov;
	float			m_aspect_ratio;
	float			m_z_near;
	float			m_z_far;
	bool			m_is_free;

	void BuildProjectionMatrix();
	void BuildViewMatrix();

public:
	Camera();
	~Camera();

	Frustum* m_frustum;

	void Init(const float fov, const float aspect_ratio, const float z_near, const float z_far);
	void Update();
	void RotateX(const float angle_x);
	void RotateY(const float angle_y);
	void MoveForward(const float displacement);
	void MoveRight(const float displacement);	
	void MoveUp(const float displacement);	
	void ResetCamera(const D3DXVECTOR3 &position, const D3DXVECTOR3 &target);
	void ResetCamera(float pos_x, float pos_y, float pos_z, float target_x, float target_y, float target_z);
	
	void SetPosition(D3DXVECTOR3 &position)		{m_position = position; BuildViewMatrix();}
	void SetPosition(float x, float y, float z)	{m_position.x = x; m_position.y = y; m_position.z = z; BuildViewMatrix();}
	void SetTarget(D3DXVECTOR3 &target)			{ResetCamera(m_position, target);}
	void SetFov(const float fov)				{if(fov > 0) {m_fov = fov; BuildProjectionMatrix();}}
	void SetFree(bool is_free = true)			{m_is_free = is_free;}

	D3DXVECTOR3		GetPosition()			{return m_position;}
	D3DXVECTOR3		GetTarget()				{return m_position + m_target;}
	D3DXVECTOR3		GetLocalTarget()		{return m_target;}
	D3DXVECTOR3		GetRight()				{return m_right;}
	D3DXMATRIXA16*	GetViewMatrix()			{return &m_matrix_view;}
	D3DXMATRIXA16*	GetProjectionMatrix()	{return &m_matrix_projection;}
	bool			IsFree()				{return m_is_free;}
};

